package ai.people.netmon.framework.domain.reddit.monitor.request;

import ai.people.netmon.framework.domain.reddit.monitor.entity.RedditUsers;
import ai.people.netmon.framework.model.request.PageKeyWordsRequest;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

/**
 * 说明
 *
 * @author zhenglin
 * @since 2022/3/15
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class QueryRequest extends PageKeyWordsRequest {

    public LambdaQueryWrapper<RedditUsers> createWrapper() {
        LambdaQueryWrapper<RedditUsers> queryWrapper = Wrappers.lambdaQuery();
        if (StringUtils.isNotBlank(this.getSearchKeywords())) {
            queryWrapper.or(x -> x.like(RedditUsers::getUserName, getSearchKeywords())
                    .or().like(RedditUsers::getName,getSearchKeywords())
                    .or().like(RedditUsers::getUrl,getSearchKeywords())
                    .or().like(RedditUsers::getDescription,getSearchKeywords())
            );
        }
        return queryWrapper;
    }
}
